package com.yixing.tech.common.tcp.channel;

import io.netty.channel.Channel;

import java.util.concurrent.ConcurrentHashMap;

public class ChannelContext {
    public static final ConcurrentHashMap<String, Channel> channelMap = new ConcurrentHashMap<>();

    public void addChannel(String ip, Channel channel) {
        channelMap.put(ip, channel);
    }

    public void removeChannel(String ip) {
        channelMap.remove(ip);
    }

    public void sendDataByChannel(String ip, String data) {
        if(ip == null || "".equals(ip) || data == null || "".equals(data))
            return;
        Channel channel = channelMap.get(ip);
        if(channel != null) {
            channel.writeAndFlush(data);
        }
    }
}
